// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import StateMachine = require("../utils/state-machine.min");

const {ccclass, property} = cc._decorator;

@ccclass
export default class testFsm extends cc.Component {

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let fsm = new StateMachine(
            {
                init: 'state_idle',
                transitions: [
                    { name: 'stop', from: '*', to: 'state_idle' },
                    { name: 'move', from: 'state_idle', to: 'state_move' },
                    { name:'attack', from: ['state_idle','state_move'],  to: 'state_attack'},
                ],
                methods: {
                    onBeforeStateMove:()=>{
                        console.log('onbeforeMove...');
                    },
                    onEnterStateMove:()=>{
                        console.log('onEnterStateMove...');
                    },
                    onMove:()=>{
                        console.log('onMove');

                        //fsm.stop();
                    },
                    onStop:()=>{
                        console.log('onStop');
                    },
                    onLeaveStateStop:()=>{
 
                    },
                }
            }
                    
        );
        console.log('onInit: '+fsm.is('state_idle'));
        if (fsm.is('state_idle')) {
            fsm.move();
        }
    }

    start () {

    }

    // update (dt) {}
}
